<template>
  <div>
    <!-- 用了一个行列布局 -->
    <el-row type="flex" justify="space-between" align="middle" style="height: 40px">
      <el-col>
        <span>{{ obj.name }}</span>
      </el-col>
      <el-col :span="4">
        <el-row type="flex" justify="end">
          <!-- 两个内容 -->
          <el-col>{{ obj.manager }}</el-col>
          <el-col>
            <!-- 下拉菜单 element -->
            <el-dropdown>
              <span>
                操作<i class="el-icon-arrow-down" />
              </span>
              <!-- 下拉菜单 -->
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="$emit('add-dept',obj)">添加子部门</el-dropdown-item>
                <el-dropdown-item v-if="isRoot" @click.native="$emit('edit-dept',obj)">查看部门</el-dropdown-item>
                <el-dropdown-item v-if="isRoot" @click.native="onDel">删除部门</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </el-col>
        </el-row>
      </el-col>
    </el-row>

  </div>
</template>

<script>
import { delDepartmentInfo } from '@/api/department'
export default {
  props: {
    obj: {
      type: Object,
      required: true
    },
    isRoot: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      addDeptFrom: {
        name: '',
        manager: '',
        code: '',
        introduce: '',
        region: ''
      }
    }
  },

  created() {

  },

  methods: {
    onDel() {
      this.$confirm('此操作将永久删除该部门, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        console.log(this.obj)
        await delDepartmentInfo(this.obj.id)
        // this.$message({
        //   type: 'success',
        //   message: '删除成功!'
        // })
      })
    }
  }
}
</script>

<style scoped lang='scss'>

</style>
